clear all 
set more off 
set maxvar 15000 
clear matrix


*** Logs
	use "$Mydirectory1/3_Output/2_PooledData_analysis.dta", clear 
    keep if baseline_sample==1
    
    levelsof decade, local(decades)
        foreach d of local decades {
        eststo clear
        
            di "`d'"
            reg log_son_baseline log_father_baseline  [aw=wgt_sex_race] if decade==`d', robust 
            estimates store log`d'
            
            local number1 = _b[log_father_baseline]+1.96*_se[log_father_baseline]
            local ub: display %-04.2fc `number1'    

            local number2 = _b[log_father_baseline]-1.96*_se[log_father_baseline]
            local lb: display %-04.2fc `number2'
            
            estadd local bounds "(`lb', `ub')"

        }
        
        label var log_father_baseline "IGE coefficient"

    
    #delimit ; 
    esttab log1910 log1920 log1930 log1940 log1950 log1960 log1970 using "$Mydirectory2/appendix_a/table_main_estimates_log.tex", replace 
    booktabs nostar label  keep(log_father_baseline) nobase noomit nonote alignment(c c) width(\hsize) se(3) b(3) brackets
    mtitles("1910" "1920" "1930" "1940" "1950" "1960" "1970") 
    stats(bounds N, fmt(0 %9.2gc) label("Lower \& Upper Bound" "Observations"));
    #delimit cr
    

*** Ranks
    levelsof decade, local(decades)
        foreach d of local decades {
        eststo clear
        
            reg rank_son_baseline rank_father_baseline [aw=wgt_sex_race] if decade==`d', robust 
            estimates store rank`d'
            
            local number1 = _b[rank_father_baseline]+1.96*_se[rank_father_baseline]
            local ub: display %-04.2fc `number1'    

            local number2 = _b[rank_father_baseline]-1.96*_se[rank_father_baseline]
            local lb: display %-04.2fc `number2'
            
            estadd local bounds "(`lb', `ub')"
            
    }
            label var rank_father_baseline "Rank coefficient"

    #delimit ; 
    esttab rank1910 rank1920 rank1930 rank1940 rank1950 rank1960 rank1970 using "$Mydirectory2/appendix_a/table_main_estimates_rank.tex", replace     booktabs nostar label  keep(rank_father_baseline) nobase noomit nonote alignment(c c) width(\hsize) se(3) b(3) brackets
    mtitles("1910" "1920" "1930" "1940" "1950" "1960" "1970") 
    stats(bounds N, fmt(0 %9.2gc) label("Lower \& Upper Bound" "Observations"));
    #delimit cr
